#include <assert.h>
#include <string.h>
#include <stdlib.h>
#include <malloc.h>
#include "SocketBuf.h"

SocketBuf::SocketBuf()
{
	buf						= 0;
	user_initted			= 0;
	from_address			= 0;
	num_bytes				= 0;
	num_bytes_successful	= 0;
	type = SOCKET_CHAR;

}

SocketBuf::SocketBuf(int user_num_bytes,
					 int user_type,
					 void *user_buf
					 )
{
	num_bytes		= user_num_bytes;
	type			= user_type;
	user_initted	= 1;
	buf			= (sm_byte *) user_buf;
	from_address	= 0;
}

SocketBuf::~SocketBuf()
{
	if (!user_initted)
	{
		if (buf)
		{
			delete[] buf;
		}
	}
}
/**************************************************************
  ************************************************************/
void
SocketBuf::setBufFromString(const char *new_value)
{
	if (!user_initted)
	{
		if (buf)
		{
			delete[] buf;
		}
	}

	user_initted = 0;

	buf = new sm_byte[strlen(new_value) + 1];
	strcpy(buf, new_value);
	num_bytes = strlen(new_value) + 1;
}
